{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/env Rscript"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# eg.1 总体均值mu的区级估计\n",
    "weight = scan(\"res/noodle.TXT\")\n",
    "summary(weight)\n",
    "result = t.test(weight, con =.95)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# eg.2 两个总体均值之差估计(mu1 - mu2)\n",
    "v = read.table(\"res/expend.txt\", header=T)\n",
    "tail(v)\n",
    "head(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v1 = v[v[, 2] == 1, 1]\n",
    "v1\n",
    "v2 = v[v[, 2] == 2, 1]\n",
    "v2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "m1 = mean(v1)\n",
    "m2 = mean(v2)\n",
    "m1\n",
    "m2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "diff = m1 - m2\n",
    "diff\n",
    "sd(v1)\n",
    "sd(v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t.test(v1, con=.95)$con\n",
    "t.test(v2, con=.95)$con\n",
    "\n",
    "t.test(v1, v2, con=.90)$conf"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
